#ifndef FASTNAV_H
#define FASTNAV_H

#include <QLabel>
#include <QRectF>
#include <QImage>
#include <QVector>
#include <QTableWidget>
#include <QWidget>
#include <QImage>
#include <QPainter>
#include <QResizeEvent>
#include <QLineF>
#include <QPointF>
#include <QMouseEvent>
#include <QAbstractScrollArea>

#include <poppler-qt4.h>

class FastNav : public QWidget{
    Q_OBJECT

public:
   FastNav(QWidget *parent = 0);
   // init Fast Nav object
   // function take a QVector<QImage> which contains all the thumb images
    void initDoc(QVector<QImage> p);
    ~FastNav();
    double getDistance();
    int getPreviewTimes();
    void setTargetPage(int t);
    int getTargetClickTimes();
    void cleanHistory();
    //QSize sizeHint();
public slots:
    //slot to set thumb size
    // w is widith and h is height
    //not been used now
    //  void setThumbSize(int w, int h);

    //slot to start Test
    void beginTest();

    //slot to stop test
    void abortTest();

    //slot handle resie
    //beacsue we are going to resize widget manually
    //resize event func will be called recursived
    //void resizeHandler(QSize size);

  protected:
    //paint event handle
    //this function should paint all thumb in a gride
    //and this function should paint preview when event happen
    void paintEvent (QPaintEvent *);
    
    //Function handle double click event
    // if a double click , set pageChanged signal to windows
    void mouseDoubleClickEvent (QMouseEvent * event);

    //Function handle mouse move event
    // if mouse moved track distance
    void mouseMoveEvent(QMouseEvent *);
    
    //Function handle resize event
    //if widget is resized recompute the grid
    // and call update()
    void resizeEvent ( QResizeEvent *);

    // if enter turn on preview display
    void enterEvent(QEvent *);
    // if leave turn off preivew display
    void leaveEvent(QEvent*);
    
  signals:
    // shse sign should be emited when a double click even happen
    void pageChanged(int currentPage);
  
  private:
    
    int currentPage;
    int lastPage;
    int mouseHover;
    bool showPreview;
    int prevWidth;
    int prevHeight;
    int thumbWidth;
    int thumbHeight;
    int rows;
    int columns;
    //bool resized;
    QVector<QImage> thumbs;
    QVector<QImage> previews;

    //Poppler::Document *doc;
    // following varibales are used for get testing data
    int previewTimes;
    double travelDistance;
    bool startTest;
    QPointF last;
    int targetPage;
    int targetClickTimes;

    //private functions
    void getGrid();
};

#endif
